package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IMemberService;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.member.MemberCreateValidate;
import com.mdd.admin.validate.member.MemberExamineValicate;
import com.mdd.admin.validate.member.MemberSearchValidate;
import com.mdd.admin.vo.member.MemberListsVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.member.Member;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@RestController
@RequestMapping("/adminapi/member")
@Api(tags = "社员管理")
public class MemberController {

    @Resource
    private IMemberService memberService;

    @GetMapping("/lists")
    @ApiOperation(value="文章列表")
    public AjaxResult<PageResult<MemberListsVo>> list(@Validated PageValidate pageValidate,
                                                        @Validated MemberSearchValidate searchValidate) {
        PageResult<MemberListsVo> vos = memberService.list(pageValidate, searchValidate);
        return AjaxResult.success(vos);
    }

    @GetMapping("/detail")
    @ApiOperation(value="赛事列详情")
    public AjaxResult<Member> detail(@RequestParam(value = "id",required = false) Integer id,
                                     @RequestParam("competitionId") Integer competitionId,
                                     @RequestParam("schedule") Integer schedule
    ) {
        Member detail = memberService.detail(id,competitionId,schedule);
        return AjaxResult.success(detail);
    }

    @Log(title = "赛事列新增")
    @PostMapping("/add")
    @ApiOperation(value="赛事列新增")
    public AjaxResult add(@Validated @RequestBody MemberCreateValidate createValidate) {
        memberService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "赛事列编辑")
    @PostMapping("/edit")
    @ApiOperation(value="赛事列编辑")
    public AjaxResult edit(@Validated @RequestBody MemberCreateValidate updateValidate) {
        memberService.edit(updateValidate);
        return AjaxResult.success();
    }

    @PostMapping("/examine")
    @ApiOperation(value="社团成员认证申请")
    public AjaxResult examine(@Validated @RequestBody MemberExamineValicate valicate){
        memberService.memberExamine(valicate);
        return AjaxResult.success();
    }
}
